package model

import (
    "git.oschina.net/hfwb/tianqi.git/tq/mssql"
    "git.oschina.net/hfwb/tianqi.git/tq/global"
    "fmt"
)

type MonitorHours struct {
    DB    *mssql.Conn   `json:"-" field:"-"`
    ID    int
    SID   string
    TT    string
    ITT   string
    BA    float64
    B5A   float64
    BC    float64
    BCMX  float64
    BCMXT string
    BCMN  float64
    BCMNT string
    AB    float64
    AA    float64
    AD    float64
    AC    float64
    AF    float64
    AE    float64
    AFMX  float64
    AEMX  float64
    AFMXT string
    ABMX  float64
    AAMX  float64
    ABMXT string
    BD    float64
    BDMX  float64
    BDMXT string
    BDMN  float64
    BDMNT string
    BP    float64
    BPMX  float64
    BPMXT string
    BPMN  float64
    BPMNT string
    UA    string
    BB    string
}

func NewMonitorHours() *MonitorHours {
    m := new(MonitorHours)
    m.DB = global.MssqlConn
    return m
}

func (this *MonitorHours) GetHistoryByStationCode(code string, limit int) (list []*MonitorMinute, err error) {
    sql := fmt.Sprintf("select top %d * from %s order by TT desc", limit, this.getTableName(code))
    fmt.Println(sql)
    rows, err := this.DB.Query(sql)
    if err != nil || rows == nil {
        return
    }
    rows.Scan(&list)
    return
}

func (this *MonitorHours) getTableName(code string) string {
    return "H" + code
}

